package com.gowants.pems.service;

import com.gowants.pems.mapper.EquipmentPartMapper;
import com.gowants.pems.mapper.EquipmentPartRecordMapper;
import com.gowants.pems.model.EquipmentPart;
import com.gowants.pems.model.EquipmentPartRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

@Service
public class EquipmentPartService {

    @Autowired
    private EquipmentPartMapper mapper;

    @Autowired
    private EquipmentPartRecordMapper partRecordMapper;

    @Transactional(rollbackFor = {Exception.class})
    public int saveEquipmentPart( EquipmentPart record ,String userId,String userName,String userPhone){
        int i=0;
        i=mapper.insert(record);
        if(i>0) {
	        EquipmentPartRecord partRecord=new EquipmentPartRecord();
	        partRecord.setId(UUID.randomUUID().toString());
	        partRecord.setPid(record.getId());
	        partRecord.setType(1);
	        partRecord.setCreateTime(record.getCreateTime());
	        partRecord.setCount(record.getCount());
	        partRecord.setCreateName(userId);
	        partRecord.setOperator(userName);
	        partRecord.setOperatorTel(userPhone);
	        partRecordMapper.insert(partRecord);
        }
        return i;
    }
}
